<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Services\Auth\UserServices;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UserController extends Controller
{
    /**
     * 登录.
     *
     * @param Request $request
     * @param UserServices $services
     * @return JsonResponse
     */
    public function login(Request $request, UserServices $services): JsonResponse
    {
        $res = $services->login($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess($res);
    }

    /**
     * 微信登录.
     *
     * @param Request $request
     * @param UserServices $services
     * @return JsonResponse
     */
    public function wxLogin(Request $request, UserServices $services): JsonResponse
    {
        $res = $services->wxLogin($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess($res);
    }

}
